/**
 * Created by Administrator on 2017/3/13.
 */

function initUpload(ele) {
    var t=this;
    this.ele=ele;
    this.showImg=function (imgUrl) {
        this.ele.find(".imgShow").css({"display":"inline-block"});
        img= this.ele.find(".imgShow img");
        img.attr("src",imgUrl);
        this.ele.find(".uploader").hide();
    };

    this.deleteImg=function () {
        this.ele.find(".imgShow img").attr("src","");
        this.ele.find(".imgShow").hide();
        this.ele.find(".uploader").show();
    };

    this.init=function () {
        /*file改变的时候触发*/
        this.ele.find('input').change(function () {
            console.log("change");
            var fileList = this.files[0];
            var oFReader = new FileReader();
            oFReader.readAsDataURL(fileList);
            oFReader.onload = function () {
                // alert(oFReader.result);
                t.showImg(oFReader.result);
            };
        });

        /*删除已经选择的图片*/
        this.ele.find(".imgShow .delete").click(function () {
            t.deleteImg();
        });
    }
}